package com.rede.didiok.admin.web;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rede.didiok.admin.entity.MessagePushEntity;
import com.rede.didiok.admin.service.MessagePushService;
import com.rede.didiok.common.constant.conf.MessageConf;
import com.rede.didiok.common.dto.user.MessagePushDto;
import com.rede.didiok.common.enums.PushMethodEnum;
import com.rede.didiok.common.utils.R;
import com.rede.didiok.common.utils.ResultUtil;

/**
 * 博客收藏 RestApi
 *
 * @author Rede
 * @date 2023年7月22日23:28:29
 */
@RestController
@RequestMapping("/admin/feign/messagePush")
@Api(value = "消息推送相关接口", tags = {"消息推送相关接口"})
@Slf4j
public class MessagePushController {
    @Autowired
    private MessagePushService messagePushService;

    @ApiOperation(value = "获取网站通知", notes = "获取网站通知")
    @PostMapping("/getWebNotice")
    public String getWebNotice() {
        log.info("通过业务id获取收藏");
        MessagePushDto messagePushVO = new MessagePushDto();
        messagePushVO.setPushMethod(String.valueOf(PushMethodEnum.ANNOUNCEMENT.getType()));
        messagePushVO.setPageSize(1L);
        messagePushVO.setCurrentPage(1L);
        IPage<MessagePushEntity> messagePushIPage = messagePushService.getPageList(messagePushVO);
        List<MessagePushEntity> messagePushList = messagePushIPage.getRecords();
        if (messagePushList.size() > 0) {
            return ResultUtil.successWithData(messagePushList.get(0));
        }
        return ResultUtil.errorWithMessage(MessageConf.ENTITY_NOT_EXIST);
    }

    /**
     * 通过 id 更新消息推送数据
     * @param messagePush
     * @return
     */
    @ApiOperation(value = "通过 id 更新消息推送数据", notes = "通过 id 更新消息推送数据")
    @PostMapping("/updateMessagePushById")
    R updateMessagePushById(@RequestBody MessagePushDto messagePush){
        MessagePushEntity messagePushEntity = new MessagePushEntity();
        BeanUtils.copyProperties(messagePush, messagePushEntity);
        return R.ok().setData(messagePushEntity.updateById());
    }
}

